package com.kx.mybatis.state;

/**
 * @Description
 * @ClassName R
 * @Author Sun
 * @Date 2021/5/15 19:24
 * @Version 1.0
 */
public class R {
    private int code; //状态码
    private String msg; //状态信息
    private Object data; //返回数据

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


    public static R setOk() {
        return setOk(null);
    }

    public static R setOk(Object data) {
        R r = new R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        r.setData(data);
        return r;
    }
    //在一个项目中,相同的状态总是返回相同的状态码
    public static R setError(){
        R r = new R();
        r.setCode(ResultCode.FAIL);
        r.setMsg("失败");
       return r;
    }

    public static R setError(int code,String msg){
        return setError(code,msg,null);

    }

    public static R setError(int code,String msg,Object data){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
}

